package com.bw.liuyushan.liuyushan20210904.Managers;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bw.liuyushan.liuyushan20210904.R;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

/**
 * Liuyushan20210904
 * file name is : MyStand
 * created by Ender on 2021/9/4 10:31.
 * author : 刘雨杉
 * Describe:
 */
public class MyStand extends StandardGSYVideoPlayer {
    long time=0;
    public MyStand(Context context, Boolean fullFlag) {
        super(context, fullFlag);
    }

    public MyStand(Context context) {
        super(context);
    }

    public MyStand(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()){
            case MotionEvent.ACTION_DOWN:
                if (time==0){//获取点击时间
                    time=System.currentTimeMillis();
                }else{
                    if (System.currentTimeMillis()-time<300){
                        ImageView imageView = new ImageView(getContext());
                        imageView.setX(event.getX());
                        imageView.setY(event.getY());
                        imageView.setImageDrawable(getContext().getDrawable(R.drawable.hartred));
                        imageView.setLayoutParams(new ViewGroup.LayoutParams(60,60));
                        addView(imageView);
                        //设置属性动画
                        ObjectAnimator scaleX = ObjectAnimator.ofFloat(imageView, "scaleX", 1, 5);
                        ObjectAnimator scaleY = ObjectAnimator.ofFloat(imageView, "scaleY", 1, 5);
                        scaleX.setDuration(400);
                        scaleY.setDuration(400);
                        scaleX.start();
                        scaleY.start();
                        scaleX.addListener(new AnimatorListenerAdapter() {
                            @Override
                            public void onAnimationEnd(Animator animation) {
                                super.onAnimationEnd(animation);
                                //消失动画
                                ObjectAnimator.ofFloat(imageView,"alpha",1,0).setDuration(300).start();
                            }
                        });
                    }else{
                        time=System.currentTimeMillis();
                    }
                }
                break;
        }
        return super.onTouch(v, event);
    }

    @Override//注释双击暂停 改为点击暂停
    protected void touchDoubleUp(MotionEvent e) {
//        super.touchDoubleUp(e);
    }

    @Override
    public int getLayoutId() {
        return R.layout.mystand;
    }
}
